﻿using DosTexPrj.Core.Models;
using FluentNHibernate.Mapping;

namespace DosTexPrj.Implement.NHibernate.Mapping
{
    public class CustomerMapping : ClassMap<Customer>
    {
        public CustomerMapping()
        {
            Table("Customers");
            Id(x => x.Id, "CustomerID").GeneratedBy.Identity().UnsavedValue(0);
            Map(x => x.Address, "Address").Not.Nullable().Length(200);
            Map(x => x.CustomerName, "CustomerName").Not.Nullable().Length(200);
            Map(x => x.PhoneNumber, "PhoneNumber").Not.Nullable().Length(20);
            HasMany<Order>(x => x.Orders).Cascade.AllDeleteOrphan()
                                           .KeyColumn("CustomerID")
                                           .AsBag().Not.LazyLoad();
        }
    }
}